package ms.core.shutdown;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import ms.core.common.ApiResult;
import ms.core.tool.EncryptTool;
import ms.core.tool.JsonTool;
import ms.core.tool.Log4j2Tool;
import ms.core.tool.PropTool;

public class Application {
	private static String SYSTEM_CONF	= "/config/server.properties";

	public static String UTF8			= "utf-8";

	public static String CLIENT_ID		= "";			// 微服务编码(和平台上配置保持一致)
	public static String SECRET_KEY		= "";			// 微服务secretKey(和平台上配置保持一致)
	public static String SERVICE_URL	= "";			// 微服务地址

	/**
	 * 加载配置参数
	 */
	public static void shutdown() {
		Log4j2Tool.info(Application.class, "正在读取微服务配置...");
		PropTool tool = PropTool.getInstance(SYSTEM_CONF);

		CLIENT_ID  	 = tool.getValue("clientId", "");
		SECRET_KEY 	 = tool.getValue("secretKey", "");
		SERVICE_URL	 = tool.getValue("serviceUrl", "");

		long time = (new Date()).getTime();
		String sign  = EncryptTool.md5Encode(CLIENT_ID+"~"+SECRET_KEY+"-"+time);
		Map<String, Object> body = new HashMap<>();
		body.put("clientId", CLIENT_ID);
		body.put("time", time);
		body.put("signature", sign);
		ApiResult ret = FeignTool.callFunc(SERVICE_URL, "shutdown", body);
		Log4j2Tool.info(Application.class, JsonTool.objectToJson(ret));
	}

	public static void main(String[] args) {
		shutdown();
	}
}
